package view
{
	import com.bit101.components.HBox;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TextEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	
	public class PriceItem extends HBox
	{
		[Embed(source="assets/components/textinput.png")]
		private var inputBg:Class;
		public var price:int;
		public var allPrice:int;
		public var num:int;
		public var data:Object;
		public function PriceItem(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
		{
			super(parent, xpos, ypos);
		}
		public function set source(obj:Object):void{
			data = obj;
			var label:TextField = new TextField();
			label.autoSize = TextFieldAutoSize.LEFT;
			label.height = 25;
			label.htmlText = "<font color='#666666' size='14'>" + obj.name + "</font>";
			this.addChild(label);
			
			var priceLabel:TextField = new TextField();
			priceLabel.autoSize = TextFieldAutoSize.LEFT;
			priceLabel.height = 25;
			priceLabel.htmlText = "<font color='#666666' size='14'>" + obj.price + "元</font>";
			this.addChild(priceLabel);
			price = int(obj.price);
			getInput();
			
		}
		private function getInput():void{
			var sp:Sprite = new Sprite;
			var bitmap:Bitmap = new inputBg();
			sp.addChild(bitmap);
			var txt:TextField = new TextField();
			txt.type = TextFieldType.INPUT;
			txt.width = 59;
			txt.height = 22;
			txt.textColor = 0x666666;
			txt.addEventListener(Event.CHANGE,onInput);
			txt.restrict = '0-9';
			sp.addChild(txt);
			this.addChild(sp);
		}
		private function onInput(event:Event):void{
			allPrice = int(event.target.text) * price;
			data.num = int(event.target.text);
			this.dispatchEvent(event);
		}
		
	}
}